#pragma once
#include "UIElement.h"
#include <vector>

namespace GUIToolkit
{
	class Panel :
		public Control
	{
	protected:
		LayoutEngine* layout;
		bool layoutSuspend;
		std::vector<UIElement*> children;

		virtual void OnLoad();
		virtual void OnPaintForeground(Graphics* g);
		virtual void OnPropertyChanged(PROPERTY p);

	public:
		Panel(float x, float y, float width, float height, LPCWSTR name = NULL);

		virtual UIElement* HitTest(PointF* p);

		void SetLayout(LayoutEngine* layout)
		{
			this->layout = layout;
			this->Layout();
		}

		int Find(UIElement* element) const;
		int Find(wstring name) const;
		void Add(UIElement* element);
		void Remove(int i);
		void Remove(UIElement* element);
		void Clear();

		void SuspendLayout()
		{
			this->layoutSuspend = true;
		}
		void ResumeLayout()
		{
			this->layoutSuspend = false;
			this->Layout();
		}
		void Layout()
		{
			if(!this->layoutSuspend && this->layout != NULL)
				this->layout->Layout(this);
		}

		UIElement* operator [](int index)
		{
			return children[index];
		}
		int Count() const
		{
			return children.size();
		}

		virtual ~Panel(void);
	};
}